<template>
  <!-- 计划选择合伙人组件 -->
  <el-dialog :title="'选择' + partnerName + ''" :visible.sync="partnerVisible" :close-on-press-escape="true" width="70%"
    top="7vh">
    <div class="bgc-default pad-20">
      <div class="search-item  mar-b-10">
        <label class="font-14"></label>
        <el-select class="select-class" v-model="searchListQuery.keywordType" style="width: 120px">
          <el-option label="合伙人名称" value="1"></el-option>
          <el-option label="联系人" value="2"></el-option>
          <el-option label="手机号" value="3"></el-option>
        </el-select>
        <el-input @keyup.enter.native="handleSearch" v-model.trim="searchListQuery.keyword" placeholder="请输入关键词"
          style="width: 280px;">
        </el-input>
        <el-button-group class="mar-l-20">
          <el-button type="primary" @click="handleSearch">查询</el-button>
          <el-button @click="resetClick">重置</el-button>
        </el-button-group>
      </div>

      <div class="scroll-layer-box">
        <!-- 内容列表 -->
        <div class="table-container">
          <el-table ref="selectPartnerMultipleTable" element-listLoading-text="加载中" style="width: 100%"
            header-cell-class-name="default-header" row-class-name="default-row" :data="partnerList"
            v-loading="selectPartnerlistLoading" @selection-change="handleSelectionChange">
            <el-table-column width="50px" type="selection" fixed="left"></el-table-column>
            <el-table-column align="center" label="合伙人名称" prop="partnerName">
            </el-table-column>
            <el-table-column align="center" label="联系人" prop="realName">
            </el-table-column>
            <el-table-column align="center" label="手机号" prop="phone">
            </el-table-column>
          </el-table>
        </div>
        <!-- 列表分页 -->
        <pagination v-show="total>0" :total="total" :page.sync="searchListQuery.currentPage"
          :limit.sync="searchListQuery.size" @pagination="pagingSelectPartnerByPlan" />
      </div>
      <div slot="footer" class="dialog-footer mar-t-10">
        <el-button type="primary" @click="handleSureSelect">确定</el-button>
        <el-button @click="handleCancel">取消</el-button>
      </div>
    </div>
  </el-dialog>
</template>

<script>
  import {
    pagingSelectPartnerByPlan
  } from '@/api/user/enterprisePartner'
  export default {
    props: {
      onSureCall: Function
    },
    data() {
      return {
        planId: '',
        partnerName: '合伙人',
        selectPartnerlistLoading: false,
        searchListQuery: {
          currentPage: 1,
          size: 20,
          keywordType: '1',
          keyword: '',
          partnerType: '1'
        },
        partnerVisible: false,
        total: 0,
        partnerList: [],
        multipleSelection: []
      }
    },
    created() {

    },
    methods: {
      // 打开选择合伙人
      // planId 计划id；partnerType:合伙人类型；
      open(planId, partnerType) {
        if (!planId) {
          this.msgError('计划id不能为空!')
          return
        }
        if (partnerType === 1) {
          this.partnerName = '一级合伙人'
        } else if (partnerType === 2) {
          this.partnerName = '二级合伙人'
        } else {
          this.partnerName = '合伙人'
        }
        this.planId = planId
        this.partnerVisible = true
        this.searchListQuery.partnerType = partnerType
        this.pagingSelectPartnerByPlan()
      },
      pagingSelectPartnerByPlan() {
        this.selectPartnerlistLoading = true
        this.searchListQuery.planId = this.planId
        this.searchListQuery.enterpriseId = this.getEnterpriseId()
        pagingSelectPartnerByPlan(this.searchListQuery).then(response => {
          this.selectPartnerlistLoading = false
          if (response.isError) return
          this.total = response.data.total
          this.partnerList = response.data.records
        })
      },
      handleSearch() {
        this.searchListQuery.currentPage = 1
        this.pagingSelectPartnerByPlan()
      },
      resetClick() {
        const originData = this.$options.data()
        this.searchListQuery = originData.searchListQuery
        this.handleSearch()
      },
      // 勾选
      handleSelectionChange(val) {
        this.multipleSelection = val
      },
      // 确认选择
      handleSureSelect() {
        if (this.multipleSelection && this.multipleSelection.length > 0) {
          this.onSureCall(this.multipleSelection)
          this.handleCancel()
        } else {
          this.msgError('请选择' + this.partnerName)
        }
      },
      // 取消
      handleCancel() {
        this.partnerVisible = false
        this.multipleSelection = []
      }
    }
  }
</script>

<style lang="less" scoped>

</style>
